﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WAV
{
	public class CodecInt : CodecInterface.ICodec
	{
		private CodecProperties properties = new CodecProperties();

		public string this[string property]
		{
			get
			{
				switch (property.ToLower())
				{
					case @"bitspersample":
						return properties.BitsPerSample.ToString();
					case @"channels":
						return properties.Channels.ToString();
					case @"loopenabled":
						return properties.LoopEnabled.ToString();
					case @"looplength":
						return properties.LoopLength.ToString();
					case @"loopstart":
						return properties.LoopStart.ToString();
					case @"samplerate":
						return properties.SampleRate.ToString();
				}
				return "";
			}
			set
			{
				switch (property.ToLower())
				{
					case @"bitspersample":
						properties.BitsPerSample = int.Parse(value);
						break;
					case @"channels":
						properties.Channels = int.Parse(value);
						break;
					case @"loopenabled":
						properties.LoopEnabled = bool.Parse(value);
						break;
					case @"looplength":
						properties.LoopLength = int.Parse(value);
						break;
					case @"loopstart":
						properties.LoopStart = int.Parse(value);
						break;
					case @"samplerate":
						properties.SampleRate = int.Parse(value);
						break;
				}
			}
		}

		public bool Decode(System.IO.Stream source, System.IO.Stream target)
		{
			return false;
		}

		public bool Encode(System.IO.Stream source, System.IO.Stream target)
		{
			if (source.Length > 0)
			{
				Encoder encoder = new Encoder(properties);
				byte[] data = new byte[source.Length];
				source.Read(data, 0, (int)source.Length);
				encoder.SetData(data);
				encoder.Encode(target);
				return true;
			}
			return false;
		}
	}
}
